//
//  Event.m
//  FH2go
//
//  Created by Hannes Feichtl on 11.06.13.
//  Copyright (c) 2013 Hannes Feichtl. All rights reserved.
//

#import "Event.h"

@implementation Event

@synthesize end;
@synthesize location;
@synthesize start;
@synthesize lecturer;
@synthesize type;
@synthesize title;

- (id)initWithDict:(NSDictionary*)dict {
    self = [super init];
    if (self) {
        if(dict == NULL) {
            self.description1 = @"";
        } else {
            location = [dict objectForKey:@"Location"];
            lecturer = [dict objectForKey:@"Lecturer"];
            type = [dict objectForKey:@"Type"];
            title = [dict objectForKey:@"Title"];
            start = [[dict objectForKey:@"Start"] intValue];
            end = [[dict objectForKey:@"End"] intValue];
            self.description1 = [NSString stringWithFormat:@"%@ / %@ / %@ / %@", self.title, self.type, self.lecturer, self.location];
            //self.description1 = @"Test";
        }
    }
    return self;
}

-(NSString*)getTitle {
    if([self.description1 isEqualToString:@""])
        return @"-";
    
    NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:self.start];
    NSDate *endDate = [NSDate dateWithTimeIntervalSince1970:self.end];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH:mm"];
    return [NSString stringWithFormat:@"%@ - %@", [dateFormatter stringFromDate:startDate],[dateFormatter stringFromDate:endDate]];

}

-(NSString*)getDesc {
    if([self.description1 isEqualToString:@""])
        return @"No lectures";
    return self.description1;
}

@end
